package com.imooc.disruptor.heigh.multi;

import com.lmax.disruptor.WorkHandler;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author yqc 2018/10/11
 */
@Data
@Slf4j
public class Consumer implements WorkHandler<Order> {

    private String consumerId;

    private static AtomicInteger count = new AtomicInteger(0);

    private Random random = new Random();

    public Consumer(String consumerId) {
        this.consumerId = consumerId;
    }

    @Override
    public void onEvent(Order event) throws Exception {
        Thread.sleep(random.nextInt(5));
        log.info("当前消费者：{}，消费信息ID：{}", this.consumerId, event.getId());
        count.incrementAndGet();
    }

    public static int getCount() {
        return count.get();
    }
}
